package Helper;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

public class Misc {

	/**
	 * Returns an array of strings with no duplicates
	 * @param strings - array to remove duplicates from 
	 * @return
	 */
	public static String[] removeDuplicates(String[] strings) {
		List<String> noDuplicates = new ArrayList<String>();
		for (String str : strings)
			if (!noDuplicates.contains(str))
				noDuplicates.add(str);
		String [] ret = new String [noDuplicates.size()];
		for (int i=0; i<noDuplicates.size(); i++)
			ret[i] = (noDuplicates.get(i));
		return ret;
	}
	
	/**
	 * 
	 * @return today's date in the format needed for insertion to the database
	 */
	public static String getTodaysDate() {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        return dateFormat.format(calendar.getTime());
	}
	
	/**
	 * Makes the string fit to the database
	 * @param str - string to fit
	 * @return
	 */
	public static String correctString(String str) {
		return str.replaceAll("'", "''");
	}

	
}
